! function(e, $, mui) {
	"use strict";
	var config = {};
	// 定义页面
	var p = function(config) {
		var t = this;
		t.config = config;
		t.userInfo = null;
		t.page = {
			page: 0,
			perpage: 0,
			more: true
		};
		t.element = {
			nickname: $('.left-nav .nickname')
		};
		// 初始化
		t.init();

		// 事件监听
		t.listen();
	};

	var pt = p.prototype;

	// 页面初始化
	pt.init = function() {
		var t = this;
		t.mapInit();

	};

	// 事件初始化
	pt.listen = function() {
		var t = this;

	};

	// 用户信息初始化
	pt.mapInit = function() {
		var t = this;
		t.page.map = new AMap.Map('container', {
			zoom: 15, //级别
			center: centerPoint, //中心点坐标
			viewMode: '2D' //使用3D视图
		});

		Geolocation(t.page.map)

		t.page.map.on('complete', function() {
			$(".amap-logo").hide();
			$(".amap-copyright").hide()
		});
		var auto = new AMap.Autocomplete({
			input: "stasion"
		});
	};
	e.page = new p(config);
	mui.init({
		keyEventBind: {
			backbutton: true //开启back按键监听
		}
	});
	// 页面初始化
	mui.plusReady(function() {

	});

}(window, $, mui);

function Geolocation(map) {
	map.plugin('AMap.Geolocation', function() {
		geolocation = new AMap.Geolocation({
			enableHighAccuracy: true, //是否使用高精度定位，默认:true
			timeout: 10000, //超过10秒后停止定位，默认：无穷大
			buttonOffset: new AMap.Pixel(10, 20), //定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
			zoomToAccuracy: false, //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
			buttonPosition: 'RB'
		});
		map.addControl(geolocation);
		geolocation.getCurrentPosition();
		AMap.event.addListener(geolocation, 'complete', function(data) {
			setBicPoints(data.position, map);
			console.log("定位成功")
		});
		AMap.event.addListener(geolocation, 'error', function(e) {
			console.log("error" + e.message);
		});
	});
}
var configJson = {};

function setBicPoints(point, map) {

	setTimeout(function() {
		configJson['points'] = [];
		var infoWindow = new AMap.InfoWindow({
			offset: new AMap.Pixel(0, -30)
		});
		for(var i = 0; i < 10; i++) {

			var a = random(i, i + 1, 5) / 1000;
			var b = random(i - 1 < 0 ? 0 : i - 1, i, 5) / 1000;
			var lng = point.getLng() + a;
			var lat = point.getLat() + b;

			if(i % 2 == 0) {
				lng = point.getLng() - a;
				lat = point.getLat() - b;
			}
			if(i % 3 == 0) {
				lng = point.getLng() + a;
				lat = point.getLat() - b;
			}

			if((lng + "").length > 10 || (lat + "").length > 10) {
				i = i - 1;
				continue;
			}
			var marker = new AMap.Marker({
				map: map,
				icon: '../../ui/home/images/bicycel.png',
				clickable: true,
				position: [lng, lat],
				offset: new AMap.Pixel(-12, -36)
			});
			marker.content = '我是第' + (i + 1) + '个Marker';
			marker.on('click', function(e) {

				var position = e.target.getPosition();

				var geocoder = new AMap.Geocoder({
					radius: 1000,
					extensions: "all"
				});
				geocoder.getAddress(position, function(status, result) {
					if(status === 'complete' && result.info === 'OK') {

						content = '<span>'+ result.regeocode.formattedAddress +'</span><br /><span>桩数：20</span><br />' +
							'<span>剩余：18</span><br /><span>距离我'+ Math.round(point.distance(position)) +'米</span><br />';
						infoWindow.setContent(content);
						infoWindow.open(map, e.target.getPosition());
					}
				});

			});
		}
		//		AMap.event.addListener(marker, 'click', function() {
		//			infoWindow.open(map, marker.getPosition());
		//		});
	}, 1000);

}

var random = function(t1, t2, t3) { //t1为下限，t2为上限，t3为需要保留的小数位
	function isNum(n) {
		return /^\d+$/.test(n);
	}
	if(!t1 || (!isNum(t1))) {
		t1 = 0;
	}
	if(!t2 || (!isNum(t2))) {
		t2 = 1;
	}
	if(!t3 || (!isNum(t3))) {
		t3 = 0;
	}
	t3 = t3 > 15 ? 15 : t3; // 小数位不能大于15位
	var ra = Math.random() * (t2 - t1) + t1,
		du = Math.pow(10, t3);
	ra = Math.round(ra * du) / du;

	return ra;
}